package com.lv.common.lce

import android.view.View
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.RelativeLayout
import android.widget.TextView
import com.lv.common.R
import com.lv.common.ktx.LoadSrc

/**
 * 作者： ygx
 * 创建日期：2023/2/14 2:37 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 * <p>
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：具体的策略
 */
class DefaultLceImpl constructor(
    private val loading: View?,
    private val loadErrorView: View?,
    private val badNetworkView: View?,
    private val noContentView: View?
) : ILce {

    override fun startLoading(tip: String, boolean: Boolean) {
        loadFinished()
        loading?.visibility = View.VISIBLE
        val tipTextView = loading?.findViewById<TextView>(R.id.tv_text)
        tipTextView?.text = tip
        tipTextView?.visibility = if (boolean) View.VISIBLE else View.GONE
    }

    override fun loadFinished() {
        loading?.visibility = View.GONE
        badNetworkView?.visibility = View.GONE
        noContentView?.visibility = View.GONE
        loadErrorView?.visibility = View.GONE
    }

    override fun showLoadErrorView(
        tip: String, resouse: Int,
        showBack: Boolean,
        callBack: View.OnClickListener?
    ) {
        loadFinished()
        val loadErrorText = loadErrorView?.findViewById<TextView>(R.id.loadErrorText)
        val mIvBack = loadErrorView?.findViewById<ImageView>(R.id.iv_back)
        val mIvError = loadErrorView?.findViewById<ImageView>(R.id.iv_error)
        loadErrorText?.text = tip
        loadErrorView?.visibility = View.VISIBLE
        mIvError?.setImageResource(resouse)
        mIvBack?.setOnClickListener(callBack)
        mIvBack?.visibility = if (showBack) View.VISIBLE else View.GONE

    }

    override fun showBadNetworkView(listener: View.OnClickListener) {
        loadFinished()
        badNetworkView?.visibility = View.VISIBLE
        badNetworkView?.setOnClickListener(listener)
    }

    override fun showNoContentView(tip: String) {
        loadFinished()
        val noContentText = noContentView?.findViewById<TextView>(R.id.noContentText)
        noContentText?.text = tip
        noContentView?.visibility = View.VISIBLE
    }

}